package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.nursing.domain.Reservation;
import com.zzyl.nursing.service.impl.ReservationServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author Lorine
 * @date 2025/3/5 14:46
 */
@RestController
@Slf4j
@Api(tags = "预约管理")
@RequestMapping("/member/reservation")
public class ReservationController extends BaseController {
    @Autowired
    private ReservationServiceImpl reservationService;

    /**
     * 分页查询预约列表
     */
    @ApiOperation("分页查询预约列表")
    @GetMapping("/page")
    public R<TableDataInfo> page(@ApiParam("分页查询预约列表") Reservation reservation) {
        startPage();
        List<Reservation> list = reservationService.selectReservationList(reservation);
        return R.ok(getDataTable(list));
    }

    /**
     * 查询当天取消预约数量
     */
    @ApiOperation("查询当天取消预约数量")
    @GetMapping(value = "/cancelled-count")
    public R<Long> getInfo() {
        return R.ok(reservationService.getCancelledCount());
    }

    /**
     * 查询每个时间段剩余预约次数
     */
    @ApiOperation("查询每个时间段剩余预约次数")
    @GetMapping(value = "/countByTime")
    public R<List<Map<String, Object>>> countByTime(@ApiParam("时间戳") Long time) {
        return R.ok(reservationService.countByTime(time));
    }

    /**
     * 新增预约
     */
    @ApiOperation("新增预约")
    @PostMapping
    public AjaxResult add(@ApiParam("预约信息") @RequestBody Reservation reservation) {
        return toAjax(reservationService.insertReservation(reservation));
    }

    /**
     * 取消预约
     */
    @ApiOperation("取消预约")
    @PutMapping("/{id}/cancel")
    public R cancel(@ApiParam("预约id") @PathVariable Long id) {
        return R.ok(reservationService.cancel(id));
    }
}
